<template>
	<div class="zuzhiguanli flex animate__animated animate__fadeIn">
    <left2></left2>

    <div style="width: calc(100vw - 220px);">
      <div class="flexc" style="padding: 30px 30px 0;">
        <div class="flexc back" style="cursor: pointer;">
          <i class="el-icon-arrow-left" ></i>
          <div @click="back()" style="margin-right: 30px;">返回</div>
        </div>
      </div>
      <div class="flexc" style="padding: 30px;">
          <el-button type="primary" icon="el-icon-plus" @click="logshow">添加定义组</el-button>
      </div>
      <div style="padding:0 30px;">
          <el-table :data="list" style="width: 100%;">
            <el-table-column align="center" prop="dingyiId" label="ID"></el-table-column>
            <el-table-column align="center" prop="dingyiName" label="定义组名称"></el-table-column>

            <el-table-column align="center" label="定义组类型">
              <template slot-scope="scope">
                <div v-if="scope.row.dingyiType == 31">定义组时域波形</div>
                <div v-if="scope.row.dingyiType == 32">定义组包络</div>
                <div v-if="scope.row.dingyiType == 33">定义组频谱</div>
              </template>
            </el-table-column>

            <el-table-column align="center" label="操作">
              <template slot-scope="scope">
                <div class="flexcc">
                  <!-- <div style="color: #0093F6; cursor: pointer; margin: 0 10px;" @click="bianji(scope.row)">修改</div> -->
                  <div style="color: #f00; cursor: pointer; margin: 0 10px;" @click="shanchu(scope.row)">删除</div>
                  <div style="color: #0093F6; cursor: pointer; margin: 0 10px;" @click="yidongshang(scope.row)">上移</div>
                  <div style="color: #0093F6; cursor: pointer; margin: 0 10px;" @click="yidongxia(scope.row)">下移</div>
                  <!-- <div style="color: #f00; cursor: pointer; margin: 0 10px;" @click="shanchu(scope.row)">删除</div> -->
                  <!-- <div style="color: #0093F6; cursor: pointer; margin: 0 10px;" @click="go('/cedian')">管理量测点</div> -->
                </div>
              </template>
            </el-table-column>
          </el-table>
      </div>
    </div>

    <el-dialog :title="logtitle" center :visible.sync="log" width="600px"  :close-on-click-modal="false" :close-on-press-escape="false" :modal-append-to-body="true">

        <!-- <div class="flexc" style="margin-bottom: 20px;">
          <div style="width: 100px; text-align: right;">定义组名称</div>
          <div><el-input v-model="all.dingyiName" style="width: 350px; margin-left: 30px;" placeholder="请输入定义组名称"></el-input></div>
        </div> -->
        <div class="flexc" style="margin-bottom: 20px;">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>波形类型</div>
          <div>
            <el-select v-model="all.dingyiType" style="width: 350px; margin-left: 30px;" @change="chushihua" clearable filterable placeholder="请选择波形类型">
                <el-option  v-for="item in xialaall.boxingleixing" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>
        <div class="flexc" style="margin-bottom: 20px;">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>信号类型</div>
          <div>
            <el-select v-model="all.xhType" :disabled="all.dingyiType == 32" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择信号类型">
                <el-option  v-for="item in xialaall.xinhaoleixing" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>

        <div class="flexc" style="margin-bottom: 20px;"  v-if="all.dingyiType == 31 || all.dingyiType == 33">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>下限频率</div>
          <div>
            <el-select v-model="all.plMin" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择下限频率">
                <el-option  v-for="item in xialaall.xiaxianpinlv" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>
        <div class="flexc" style="margin-bottom: 20px;"  v-if="all.dingyiType == 31 || all.dingyiType == 33">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>上限频率</div>
          <div>
            <el-select v-model="all.plMax" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择上限频率">
                <el-option  v-for="item in xialaall.shangxianpinlv" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>
        <div class="flexc" style="margin-bottom: 20px;"  v-if="all.dingyiType == 31">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>波形长度</div>
          <div>
            <el-select v-model="all.bxCd" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择波形长度">
                <el-option  v-for="item in xialaall.boxingchangdu" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>
        <div class="flexc" style="margin-bottom: 20px;" v-if="all.dingyiType == 32 || all.dingyiType == 33">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>谱线数</div>
          <div>
            <el-select v-model="all.pinpu" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择谱线数">
                <el-option  v-for="item in xialaall.puxianshu" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>
        <div class="flexc" style="margin-bottom: 20px;" v-if="all.dingyiType == 33">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>平均方式</div>
          <div>
            <el-select v-model="all.pjType" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择平均方式">
                <el-option  v-for="item in xialaall.pingjunfangshi" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>
        <div class="flexc" style="margin-bottom: 20px;" v-if="all.dingyiType == 33">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>平均次数</div>
          <div>
            <el-select v-model="all.pjNum" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择平均次数">
                <el-option  v-for="item in xialaall.pingjuncishu" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>
        <div class="flexc" style="margin-bottom: 20px;" v-if="all.dingyiType == 33">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>加窗方式</div>
          <div>
            <el-select v-model="all.jcType" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择加窗方式">
                <el-option  v-for="item in xialaall.jiachuangfangshi" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>
        <div class="flexc" style="margin-bottom: 20px;" v-if="all.dingyiType == 33">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>重叠率</div>
          <div>
            <el-select v-model="all.overlay" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择重叠率">
                <el-option  v-for="item in xialaall.chongdielv" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>

        <div class="flexc" style="margin-bottom: 20px;"  v-if="all.dingyiType == 32">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>带宽</div>
          <div>
            <el-select v-model="all.dk" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择带宽">
                <el-option  v-for="item in xialaall.kuandai" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>

        <div class="flexc" style="margin-bottom: 20px;" v-if="all.dingyiType == 32">
          <div style="width: 100px; text-align: right;"><span style="color: #f00; margin-right: 5px;">*</span>分析频率</div>
          <div>
            <el-select v-model="all.fxPl" style="width: 350px; margin-left: 30px;"  clearable filterable placeholder="请选择分析频率">
                <el-option  v-for="item in xialaall.fenxipinlv" :key="item.value" :label="item.label" :value="item.value * 1"></el-option>
            </el-select>
          </div>
        </div>

    	  <span slot="footer" class="dialog-footer">
          <el-button type="danger" round @click="log = false">取消</el-button>
          <el-button type="danger" round @click="add">确定</el-button>
    	  </span>
    </el-dialog>

	</div>
</template>

<script>
  import { postxiala,updingyi,downdingyi,removedingyi,updatedingyi,adddingyi,getdiyizu } from '@/api/xitong'
 
  import left2 from '@/view/left2.vue'
	export default {
		name: 'zuzhiguanli',
    components:{
      left2
    },
		data() {
			return {
        all:{
          "dingyiType":"",
          "xhType":"",
          "plMin":"",
          "plMax":"",
          "bxCd":"",
          dingyiName:"",
          dingyiId:"",
          pinpu:"",
          pjType:"",
          jcType:"",
          pjNum:"",
          overlay:"",
          dk:"",
          fxPl:""
        },
        list:[],
        search:{
          page:1,
          page_size:20,
        },
        total:0,

        log:false,
        logtitle:"",

        xialaall:{
          boxingleixing:"",
          xinhaoleixing:"",
          boxingchangdu:"",
          xiaxianpinlv:"",
          shangxianpinlv:"",
          puxianshu:"",
          pingjunfangshi:"",
          pingjuncishu:"",
          jiachuangfangshi:"",
          chongdielv:"",
          kuandai:"",
          fenxipinlv:""
        },

			}
		},
		created() {
      this.getlist()
      this.getxialalist()
		},
		mounted() {

		},
		methods: {

      yidongshang:function(item){
        let url = '/api/dingyi/up/'+item.dingyiId
        updingyi(url).then(response => {
          this.$message.success('上移成功');
          this.getlist()
        })
      },
      yidongxia:function(item){
        let url = '/api/dingyi/down/'+item.dingyiId
        downdingyi(url).then(response => {
          this.$message.success('下移成功');
          this.getlist()
        })
      },


      shanchu:function(item){
        this.$confirm('此操作将永久删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          removedingyi(item.dingyiId).then(response => {
            this.$message.success('删除成功');
            this.getlist()
          })
        })
      },

      bianji:function(item){
        this.logtitle = '修改定义组'

        this.all = {
          "dingyiType":item.dingyiType,
          dingyiName:item.dingyiName,
          dingyiId:item.dingyiId,
          "xhType":item.xhType,
          "bxCd":item.bxCd,
          "plMin":item.plMin,
          "plMax":item.plMax,
          pinpu:item.pinpu,
          pjType:item.pjType,
          pjNum:item.pjNum,
          jcType:item.jcType,
          overlay:item.overlay,
          dk:item.dk,
          fxPl:item.fxPl
        }
        this.log = true

      },
      chushihua:function(){
        this.all.plMin = ""
        this.all.plMax = ""
        this.all.bxCd = ""
        this.all.pinpu = ""
        this.all.pjType = ""
        this.all.jcType = ""
        this.all.overlay = ""
        this.all.dk = ""
        this.all.fxPl = ""
        this.all.pjNum = ""

        if(this.all.dingyiType == 32){
          this.all.xhType = 1
        }
      },
      logshow:function(){
        this.logtitle = '新增定义组'
        this.all = {
          "dingyiType":"",
          dingyiName:"",
          dingyiId:"",
          "xhType":"",

          "bxCd":"",
          "plMin":"",
          "plMax":"",
          pinpu:"",
          pjType:"",
          pjNum:"",
          jcType:"",
          overlay:"",
          dk:"",
          fxPl:""
        }
        this.log = true
      },

      add:function(){
        // if(this.all.dingyiType == 32){
        //   if(!this.all.xhType || !this.all.pinpu || !this.all.dk || !this.all.fxPl){
        //     this.$message.error('请填写完整参数');
        //     return
        //   }
        // }
        // if(this.all.dingyiType == 33){
        //   if(!this.all.plMin || !this.all.plMax || !this.all.pinpu || !this.all.pjType || !this.all.pjNum || !this.all.jcType || !this.all.overlay){
        //     this.$message.error('请填写完整参数');
        //     return
        //   }
        // }
        // if(this.all.dingyiType == 31){
        //   if(!this.all.plMin || !this.all.plMax || !this.all.bxCd ){
        //     this.$message.error('请填写完整参数');
        //     return
        //   }
        // }
        if(this.all.dingyiId){
          updatedingyi(this.all).then((response)=>{
            this.$message.success('修改成功');
            this.log = false
            this.getlist()
          })
        }else{
          adddingyi(this.all).then((response)=>{
            this.$message.success('新增成功');
            this.log = false
            this.getlist()
          })

        }
      },

      getlist:function(){

        getdiyizu(this.all).then((response)=>{
          this.list = response.data
        })
      },

      fanye:function(val){
        this.search.page = val
        this.getlist()
      },


      //获取下啦数据用
      getxialalist:function(){
        let obj = {
          sysName:"系统配置",
          dictName:"采集定义组-信号类型",
          dictType:""
        }
        postxiala(obj).then(response => {
          this.xialaall.xinhaoleixing = response.data
        })


        let obj2 = {
          sysName:"系统配置",
          dictName:"采集定义组-波形长度",
          dictType:""
        }
        postxiala(obj2).then(response => {
          this.xialaall.boxingchangdu = response.data
        })


        let obj3 = {
          sysName:"系统配置",
          dictName:"采集定义组-上限频率",
          dictType:""
        }
        postxiala(obj3).then(response => {
          this.xialaall.shangxianpinlv = response.data
        })


        let obj4 = {
          sysName:"系统配置",
          dictName:"采集定义组-下限频率",
          dictType:""
        }
        postxiala(obj4).then(response => {
          this.xialaall.xiaxianpinlv = response.data
        })


        let obj5 = {
          sysName:"系统配置",
          dictName:"采集定义组-波形类型",
          dictType:""
        }
        postxiala(obj5).then(response => {
          this.xialaall.boxingleixing = response.data
        })


        let obj6 = {
          sysName:"系统配置",
          dictName:"采集定义组-谱线数",
          dictType:""
        }
        postxiala(obj6).then(response => {
          this.xialaall.puxianshu = response.data
        })


        let obj7 = {
          sysName:"系统配置",
          dictName:"采集定义组-平均方式",
          dictType:""
        }
        postxiala(obj7).then(response => {
          this.xialaall.pingjunfangshi = response.data
        })


        let obj8 = {
          sysName:"系统配置",
          dictName:"采集定义组-平均次数",
          dictType:""
        }
        postxiala(obj8).then(response => {
          this.xialaall.pingjuncishu = response.data
        })

        let obj9 = {
          sysName:"系统配置",
          dictName:"采集定义组-加窗方式",
          dictType:""
        }
        postxiala(obj9).then(response => {
          this.xialaall.jiachuangfangshi = response.data
        })

        let obj10 = {
          sysName:"系统配置",
          dictName:"采集定义组-重叠率",
          dictType:""
        }
        postxiala(obj10).then(response => {
          this.xialaall.chongdielv = response.data
        })


        let obj11 = {
          sysName:"系统配置",
          dictName:"采集定义组-带宽",
          dictType:""
        }
        postxiala(obj11).then(response => {
          this.xialaall.kuandai = response.data
        })


        let obj12 = {
          sysName:"系统配置",
          dictName:"采集定义组-分析频率",
          dictType:""
        }
        postxiala(obj12).then(response => {
          this.xialaall.fenxipinlv = response.data
        })
      },
		}
	}
</script>


<style scoped >

</style>
